﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace MDS
{
    public class StockRangeSetting
    {
        public StockExchange Exchange{get;private set;}
        public StkType StkType { get; private set; }
        public TradeType TradeType { get; private set; }
        public List<StkIdRange> StkIdRanges { get; private set; }

        public StockRangeSetting(
            StockExchange exchange, 
            StkType stkType, 
            TradeType tradeType,
            IEnumerable<StkIdRange> stkIdRanges)
        {
            Contract.Requires(stkIdRanges != null);
            Contract.Requires(stkIdRanges.Any());
            this.Exchange = exchange;
            this.StkType = stkType;
            this.TradeType = tradeType;
            this.StkIdRanges = stkIdRanges.ToList();
        }
        public bool IsMatch(string stkIdStr)
        {
            int stkId;
           bool s= int.TryParse(stkIdStr, out stkId);
           if (s)
               return IsMatch(stkId);
           else
               return false;
        }
        public bool IsMatch(int stkId)
        {
            if (this.StkIdRanges.Any(range => stkId <= range.EndId && stkId >= range.StartId))
                return true;
            else
                return false;
        }
    }
}
